/* 文件上传 */
var content = $("#currContent").val();
var warePicPath = $("#picPath").val();

function createUploaderIDCard() {
	var uploader = new qq.FileUploader({
		action : content+'/common/uploadImg.shtm',
		element : document.getElementById('ID_uploader'),
		allowedExtensions : [ 'jpg', 'gif', 'png' ],
		acceptFiles : [ 'image/*' ],
		uploadButtonText : "",
		uploadButtonID : "IDImgUploadBtn",
		buttonClass : "grxxform-zgzs-add fl",
		debug : false,
		sizeLimit : 10 * 1024 * 1024,
		fileNumLimit :2,
		ifOverrange:ifOverrange,
		params : {
			fileType : "img",
			proVal : "TEACHER_IDCARD_PATH"
		},
		stopOnFirstInvalidFile : false,
		addtolistcallback : callback_addtolistID,
		onProgress : callback_progressID,
		onComplete : callback_completeID
	});
}

function ifOverrange (limit){
	if ($('div[id^=IDImgDiv_]').length >= limit) {
			var tip = "只允许上传"+limit+"张以内的图片";
			if(limit==1){
				tip = "只允许上传1张图片";
			}
		alert(tip);
		return true;
	}
	return false;
}
function callback_addtolistID(id, fileName) {
 	$("#IDcard").append(showAddToListID(id, fileName, "IDImg"));
}
function callback_progressID(id, fileName, loaded, total) {
 	showprogressID(id, fileName, loaded, total, "IDImg");
}
function callback_completeID(id, fileName, result) {
 	showcompleteID(id, fileName, result, "IDImg");
  //console.log("complete:"+id);
}
function showprogressID(id, fileName, loaded, total, elePre) {
	var percent = Math.round(loaded / total * 100)
	var width = 2 * percent;
	var proBarDivID = elePre+"Div_" + id ;
	$("#" + proBarDivID).html(
		"<img src='"+content+"/images/upload/waiting.gif'>"+
		"<span class=\"ml20\">"+ percent + "%<\/span>");
}
function showAddToListID(id, fileName, elePre) {
	var str = "";
	str = " <div class=\"grxxform-zgzs-pic fl pr\" id=\"" + elePre+"Div_" + id +"\">";
	//str += "<em class=\"abs grxxform-zgzs-close\"></em></div>";
	return str;

}
function showcompleteID(id, fileName, result, elePre) {
	var reg = new RegExp("\.jpg|\.gif|\.png", "g");
	var desc = fileName.toLowerCase().replace(reg, "");
	var imgAreaDivId = elePre+"Div_" + id;
	var subid = $("#" + imgAreaDivId);
	if (result.success == 'true') {
		var str = "";
		if(elePre=="IDImg"){
			str += "<img style=\"width:217px;height:132px;\"  src=\""+warePicPath+result.imagePath+"\" \/>";
			//str +="<em class=\"abs grxxform-zgzs-close\"></em>";
		}
		subid.html(str);
		subid.append('<input type="hidden" name="orginName" value='+fileName+'><input type="hidden" name="'+elePre+'_imageSaveName" value="'+ result.saveName +'" />');
		//身份证是否有图
		 var IDcardDiv = document.getElementById("IDcard");
		 var IDdiv_s = IDcardDiv.getElementsByTagName("div");
		 if(IDdiv_s.length>=1){
			 $("#IDImgage").removeClass("grxxform-zgzs-tip fl");
			 $("#IDImgage").addClass("grxxform-zgzs-aip fl");
		 }else{
			 $("#IDImgage").removeClass("grxxform-zgzs-aip fl");
			 $("#IDImgage").addClass("grxxform-zgzs-tip fl");
		 }
		 $('#'+imgAreaDivId).attr('onmouseover','javascript:onMouseOver('+'\''+imgAreaDivId+'\''+');');
			$('#'+imgAreaDivId).attr('onmouseleave','javascript:onMouseOut('+'\''+imgAreaDivId+'\''+');');
	} else {
		
		if(result.error&&window.console){
			$("#IDImgage").removeClass("grxxform-zgzs-aip fl");
			$("#IDImgage").addClass("grxxform-zgzs-tip fl");
			alert("上传失败！错误："+result.error);
		}
		$("#" + imgAreaDivId ).remove();
	}
}
function onMouseOver(id){
	if($("#"+id).find("em").length==0){
		$("#"+id).append('<em class="abs grxxform-zgzs-close"></em>');
	}
}
function onMouseOut(id){
	$("#"+id).find("em").remove();
}
/* 文件上传结束 */